﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>自动发起</title>
    <link href="../../Scripts/easyUI145/themes/icon.css" rel="stylesheet" type="text/css" />
    <link href="../../Scripts/easyUI145/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/easyUI145/jquery.min.js" type="text/javascript"></script>
    <script src="../../Scripts/easyUI145/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <script src="DDLBar.js" type="text/javascript"></script>

    <link href="../../Style/skin/adminfont/iconfont.css" rel="stylesheet" />
    <link href="../../Style/skin/css/Default.css" rel="stylesheet" />
    <script src="../EnumLab.js"></script>
    <script type="text/javascript">

        var entityType = 2;
        var frmTreeNo = "";
        var module = null;
        $(function () {

            var moduleNo = GetQueryString("ModuleNo");

            //设置树的编号,树的编号与系统编号一致.
            module = new Entity("BP.CCFast.CCMenu.Module", moduleNo);
            frmTreeNo = module.SystemNo;

            InitBar(MenuModel.DictCopy);

            //查询出来当前系统下的表单s.
            var mds = new Entities("BP.Sys.MapDatas");
            mds.Retrieve("FK_FormTree", module.SystemNo);

            console.log(mds);

            //绑定.
            GenerBindDDL("DDL_Dicts", mds, "No", "Name");

        });

        //设置数据.
        function SetValByDDL() {

            var val = $("#DDL_Dicts").val();

            var md = new Entity("BP.Sys.MapData", val);

            $("#TB_PTable").val(md.PTable);
            $("#TB_No").val(val + "Copy");
            $("#TB_Name").val(md.Name + "Copy");

            // var val = $("#select").find("option:selected").text();
            //$("TB_Name").val(val + "Copy");
        }

        function Save() {

            var name = document.getElementById("TB_Name").value;
            var no = document.getElementById("TB_No").value;
            var pTable = document.getElementById("TB_PTable").value;
            if (pTable == "" || no === "" || name === "") {
                alert("必填项不能为空.");
                return;
            }

            var frmDict = new Entity("BP.CCBill.FrmDict");
            frmDict.No = no;
            if (frmDict.IsExits() == true) {
                alert("表单ID:" + no + "已经存在.");
                return;
            }

            $("#Msg").html("正在创建,请稍后......");

            var isSetReadonly = false;
            if (document.getElementById("CB_IsReadonly").checked == true)
                isSetReadonly = true;

            var isCopyMethonds = false;
            if (document.getElementById("CB_IsCopyMethonds").checked == true)
                isCopyMethonds = true;

            var frmID = $("#DDL_Dicts").val();
            var frmDict = new Entity("BP.CCBill.FrmDict", frmID);
           // var data = frmDict.DoMethodReturnString("DoCopyTemplate", no, name, pTable, isSetReadonly, isCopyMethonds);
            var data = frmDict.DoMethodReturnString("DoCopyTemplate", no, name, pTable);

            if (data.indexOf('err@') >= 0) {
                $("#Msg").html("<font color=red>" + data + "</font>");
                return;
            }

            $("#Msg").html("<font color=green>" + data + "</font>");
            data = data.replace('url@', '');

            //更新节点表单类型.
            var moduleNo = GetQueryString("ModuleNo");
            var en = new Entity("BP.CCFast.CCMenu.Menu");
            en.ModuleNo = moduleNo;
            en.SystemNo = module.SystemNo; //系统编号.
            en.Name = $("#TB_Name").val();
            en.UrlExt = $("#TB_No").val();

            en.MenuModel = MenuModel.Dict; //类型为.

            //查看的模式.
            if (document.getElementById("RB_ListModel_0").checked == true)
                en.ListModel = 0;
            else
                en.ListModel = 1;

            en.WorkType = "0"; //自定义菜单.
            en.Insert();

            SetHref("../../Comm/En.htm?EnName=BP.CCFast.CCMenu.Menu&No=" + en.No);

            //  alert("创建成功，您可以在在菜单里执行高级编辑与授权.");
            //  SetHref( "../Menus.htm";
            // window.close();
        }

        function GenerPinYin() {

            //是否是全拼.
            var isQuanPin = 0;
            if (document.getElementById("RB_ZZMM_0").checked == true)
                isQuanPin = 1;

            // var name = $('#TB_Nam').val();
            var name = document.getElementById("TB_Name").value;
            if (name == "")
                return;

            var handler = new HttpHandler("BP.WF.HttpHandler.Admin_CCFormDesigner");
            handler.AddPara("IsQuanPin", isQuanPin);
            handler.AddPara("TB_Name", encodeURIComponent(name));
            var data = handler.DoMethodReturnString("NewFrmGuide_GenerPinYin");

            $("#Msg").html("");

            if (data.indexOf('err@') >= 0) {
                $("#Msg").html("<font color=red>" + data + "</font>");
                return;
            }
            var webUser = new WebUser();
            var keyOrg = webUser.FK_Dept + "_CCFrm_" + data;
            var key = "CCFrm_" + data;

            var frmType = $("#DDL_FrmType").val();
            if (frmType != "3" && frmType != "7") {

                if (entityType == 0)
                    key = "Frm_" + data;
                if (entityType == 1)
                    key = "Bill_" + data;
                if (entityType == 2)
                    key = "Dict_" + data;
                keyOrg = webUser.OrgNo + "_" + key;
            }


            $('#TB_No').val(key);
            $('#TB_PTable').val(key);
            // 没有高明白.
            //   $('#TB_No_Org').val(keyOrg);
            //   $('#TB_PTable_Org').val(keyOrg);
            return;
        }
    </script>
</head>
<body>
    <form id="CCForm">
        <div id="bar">
        </div>
        <fieldset>
            <legend>复制实体表单 </legend>
            <table>
                <tr>
                    <td>选择要复制的实体 </td>
                    <td> <select id="DDL_Dicts" onchange="SetValByDDL()"> </select></td>
                </tr>

                <tr>
                    <td>新实体名称 </td>
                    <td>  <input type="text" value="" id="TB_Name" name="TB_Name" onblur="GenerPinYin()" /></td>
                </tr>

                <tr>
                    <td>新实体编号 </td>
                    <td>
                        <input type="text" value="" id="TB_No" name="TB_No" />
                    </td>
                </tr>

                <tr>
                    <td> 表单类型 </td>
                    <td>
                        <select id="DDL_FrmType">
                            <option value="0" selected="selected">经典表单</option>
                            <option value="8">开发者表单</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>存储表</td>
                    <td>
                        <input type="text" value="" id="TB_PTable" name="TB_PTable" />
                        <br />
                        系统允许不同的实体存储到同一个表里.
                        <!--<input type="text" id="TB_PTable_Org" name="TB_PTable_Org" style="width: 100%;" hidden=hidden />-->
                    </td>
                </tr>

                <tr>
                    <td colspan="2">

                        <label> <input type="checkbox" id="CB_IsReadonly" checked="checked" value="1" /> 导入后字段是否设置为只读？</label>
                        <br />
                        <label> <input type="checkbox" id="CB_IsCopyMethonds" value="1" /> 是否copy方法？</label>

                    </td>
                </tr>

                <tr>
                    <td> 列表模式</td>
                    <td>
                        <input id="RB_ListModel_0" type="radio" name="RB_ListModel" value="0" /><label for="RB_ListModel_0">编辑模式</label>
                        <input id="RB_ListModel_1" type="radio" name="RB_ListModel" value="1" checked="checked"  /><label for="RB_ListModel_1">视图模式</label>
                    </td>
                </tr>

                <tr>
                    <td colspan="2">
                        备注：创建后，可以设置查询条件，增加删除字段。
                    </td>
                </tr>
            </table>
            <br />
            <input type="button" id="Btn_Save" name="Btn_Save" value="执行复制" onclick="Save();" />
            <div id="Msg"></div>
        </fieldset>

        <fieldset>
            <legend id="help"></legend>
            <ul>
                <li> 定义：自动启动工作流程，一个流程的开始节点的填写与发起是在特定规则的设置下自动发起的流程。</li>
                <li> 解释：通常模式下的流程启动是手工的启动，就是用户从一个发起列表，点击流程名字，就启动了该流程。但是有的时候，是系统自动发起该流程。</li>

                <li>应用场景</li>
                <li> 1 周例会流程，用户希望每个周都要启动例会通知流程这个启动是让系统自动发起而非人工发起。</li>
            </ul>
        </fieldset>
    </form>
</body>
</html>
